import java.util.Objects;
import java.util.Stack;

// 最小栈
// https://leetcode.cn/problems/min-stack/
class MinStack {

    private Stack<Integer> stack1;
    private Stack<Integer> minStack;
    public MinStack() {
        stack1 = new Stack<>();
        minStack = new Stack<>();
    }
    
    public void push(int val) {
        if (stack1.empty()) {
            stack1.push(val);
            minStack.push(val);
        } else {
            if (val <= minStack.peek()) {
                stack1.push(val);
                minStack.push(val);
            } else {
                stack1.push(val);
            }
        }
    }
    
    public void pop() {
        if (!stack1.empty()) {
            int x = stack1.pop();
            if (x == minStack.peek()) {
                minStack.pop();
            }
        }
    }
    
    public int top() {
        if (!stack1.empty()) {
            return stack1.peek();
        }
        return -1;
    }
    
    public int getMin() {
        if (!minStack.empty()) {
            return minStack.peek();
        }
        return -1;
    }
}